﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:m="clr-namespace:MetroWPF.Controls">
    <Style TargetType="{x:Type m:TextBox}">
        <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
        <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBoxForegroundThemeBrush}" />
        <Setter Property="Background" Value="{DynamicResource TextBoxBackgroundThemeBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderThemeBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type m:TextBox}">
                    <Grid SnapsToDevicePixels="True">
                        <Grid.Resources>
                            <Style x:Name="DeleteButtonStyle" TargetType="Button">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="Button">
                                            <Grid>
                                                <Border x:Name="BorderElement" BorderBrush="{DynamicResource TextBoxButtonBorderThemeBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
                                                <Border x:Name="BackgroundElement" Background="{DynamicResource TextBoxButtonBackgroundThemeBrush}" Margin="{TemplateBinding BorderThickness}">
                                                    <TextBlock x:Name="GlyphElement" Foreground="{DynamicResource TextBoxButtonForegroundThemeBrush}" VerticalAlignment="Center" HorizontalAlignment="Center"
                                                               Text=" &#xE0A4; " FontFamily="{DynamicResource SymbolThemeFontFamily}" />
                                                </Border>
                                            </Grid>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter TargetName="BackgroundElement" Property="Background" Value="{DynamicResource TextBoxButtonPointerOverBackgroundThemeBrush}" />
                                                    <Setter TargetName="BackgroundElement" Property="BorderBrush" Value="{DynamicResource TextBoxButtonPointerOverBorderThemeBrush}" />
                                                    <Setter TargetName="GlyphElement" Property="Foreground" Value="{DynamicResource TextBoxButtonPointerOverForegroundThemeBrush}" />
                                                </Trigger>
                                                <Trigger Property="IsPressed" Value="True">
                                                    <Setter TargetName="BackgroundElement" Property="Background" Value="{DynamicResource TextBoxButtonPressedBackgroundThemeBrush}" />
                                                    <Setter TargetName="BackgroundElement" Property="BorderBrush" Value="{DynamicResource TextBoxButtonPressedBorderThemeBrush}" />
                                                    <Setter TargetName="GlyphElement" Property="Foreground" Value="{DynamicResource TextBoxButtonPressedForegroundThemeBrush}" />
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Border x:Name="BackgroundElement"  Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" />
                        <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" />
                        <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
                        <ContentPresenter x:Name="WaterMark" Content="{TemplateBinding WaterMark}" Margin="{TemplateBinding Padding}" Opacity="0" IsHitTestVisible="False" />
                        <Button x:Name="PART_DeleteButton" Style="{DynamicResource DeleteButtonStyle}" BorderThickness="{TemplateBinding BorderThickness}"
                                Focusable="False" IsTabStop="False" Grid.Column="1" Visibility="Collapsed" FontSize="{TemplateBinding FontSize}" VerticalAlignment="Stretch" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource TextBoxDisabledBackgroundThemeBrush}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource TextBoxDisabledBorderThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextBoxDisabledForegroundThemeBrush}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocused" Value="False">
                            <Setter TargetName="BackgroundElement" Property="Opacity" Value="{DynamicResource TextControlBackgroundThemeOpacity}" />
                            <Setter TargetName="BorderElement" Property="Opacity" Value="{DynamicResource TextControlBorderThemeOpacity}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsKeyboardFocused" Value="False" />
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition SourceName="PART_DeleteButton" Property="IsMouseOver" Value="False" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="BackgroundElement" Property="Opacity" Value="{DynamicResource TextControlPointerOverBackgroundThemeOpacity}" />
                            <Setter TargetName="BorderElement" Property="Opacity" Value="{DynamicResource TextControlPointerOverBorderThemeOpacity}" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="True" />
                                <Condition Property="IsReadOnly" Value="False" />
                                <Condition Property="IsNull" Value="False" />
                                <Condition Property="IsKeyboardFocused" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_DeleteButton" Property="Visibility">
                                <Setter.Value>
                                    <Visibility>Visible</Visibility>
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsNull" Value="True" />
                                <Condition Property="IsFocused" Value="False" />
                                <Condition Property="IsEnabled" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="WaterMark" Property="Opacity" Value="{DynamicResource TextBoxWaterMarkThemeOpacity}" />
                        </MultiTrigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter  Property="BorderBrush" Value="{DynamicResource ControlValidationInvalidThemeBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsInactiveSelectionHighlightEnabled" Value="True" />
                    <Condition Property="IsSelectionActive" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type TextBox}">
        <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
        <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
        <Setter Property="Foreground" Value="{DynamicResource TextBoxForegroundThemeBrush}" />
        <Setter Property="Background" Value="{DynamicResource TextBoxBackgroundThemeBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderThemeBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid SnapsToDevicePixels="True">
                        <Border x:Name="BackgroundElement"  Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" />
                        <Border x:Name="BorderElement" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="2" />
                        <ScrollViewer x:Name="PART_ContentHost" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Background" Value="{DynamicResource TextBoxDisabledBackgroundThemeBrush}" />
                            <Setter Property="BorderBrush" Value="{DynamicResource TextBoxDisabledBorderThemeBrush}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextBoxDisabledForegroundThemeBrush}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocused" Value="False">
                            <Setter TargetName="BackgroundElement" Property="Opacity" Value="{DynamicResource TextControlBackgroundThemeOpacity}" />
                            <Setter TargetName="BorderElement" Property="Opacity" Value="{DynamicResource TextControlBorderThemeOpacity}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsKeyboardFocused" Value="False" />
                                <Condition Property="IsMouseOver" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="BackgroundElement" Property="Opacity" Value="{DynamicResource TextControlPointerOverBackgroundThemeOpacity}" />
                            <Setter TargetName="BorderElement" Property="Opacity" Value="{DynamicResource TextControlPointerOverBorderThemeOpacity}" />
                        </MultiTrigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter  Property="BorderBrush" Value="{DynamicResource ControlValidationInvalidThemeBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsInactiveSelectionHighlightEnabled" Value="True" />
                    <Condition Property="IsSelectionActive" Value="False" />
                </MultiTrigger.Conditions>
                <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>